local dabian = fk.CreateSkill{
  name = "lingling__dabian",
}

Fk:loadTranslationTable{
  ["lingling__dabian"] = "大变",
  [":lingling__dabian"] = "准备阶段，你可以令所有角色各摸一张牌或各弃置一张手牌，若本轮有角色死亡，则此次你的摸牌数或其他角色的弃牌数翻倍。",

  ["lingling__dabian-draw"] = "所有角色各摸一张牌%arg",
  ["lingling__dabian-discard"] = "所有角色各弃置一张手牌%arg",
}

dabian:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(dabian.name) and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local str1, str2 = "",""
    if #room.logic:getEventsOfScope(GameEvent.Death, 1, function (e)
      return true
    end, Player.HistoryRound) > 0 then
      str1 = "（你摸两张）"
      str2 = "（其他角色弃两张）"
    end
    local all_choices = { "lingling__dabian-draw:::"..str1, "lingling__dabian-discard:::"..str2, "Cancel" }
    local choices = table.simpleClone(all_choices)
    if not table.find(room.alive_players, function (p)
      return not p:isKongcheng()
    end) then
      table.remove(choices, 2)
    end
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = dabian.name,
      all_choices = all_choices,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice, tos = room:getAlivePlayers()})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    local num1,num2 = 1,1
    if #room.logic:getEventsOfScope(GameEvent.Death, 1, function (e)
      return true
    end, Player.HistoryRound) > 0 then
      num2 = 2
    end
    p(choice)
    p(string.find(choice, "draw"))
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead then
        if string.find(choice, "draw") then
          if p == player then
            p:drawCards(num2, dabian.name)
          else
            p:drawCards(num1,dabian.name)
          end
        else
          if p == player then
            room:askToDiscard(p, {
              min_num = num1,
              max_num = num1,
              include_equip = false,
              skill_name = dabian.name,
              cancelable = false,
            })
          else
            room:askToDiscard(p, {
              min_num = num2,
              max_num = num2,
              include_equip = false,
              skill_name = dabian.name,
              cancelable = false,
            })
          end
        end
      end
    end
  end,
})

return dabian
